/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TIMELINE_NAPI_H
#define TIMELINE_NAPI_H

#include "napi/native_api.h"
#include "napi/native_node_api.h"

#include "timeline_client.h"
#include "timeline_callback_stub.h"
#include "itimeline_callback.h"
#include "timeline_event.h"
#include "timeline_data_utils.h"

namespace OHOS {
namespace Msdp {
class TimelineCallback : public TimelineCallbackStub{
public:
    explicit TimelineCallback() {};
    virtual ~TimelineCallback() {};
    void OnTimelineChanged(const TimelineDataUtils::TimelineData& timelineData) override;

private:
    // TO-DO, store latest timeline info
    // TimelineDataUtils::TimelineValue value_;
};

class TimelineNapi : public TimelineEvent {
public:
    explicit TimelineNapi(napi_env env, napi_value thisVar);
    virtual ~TimelineNapi();

    static napi_value Init(napi_env env, napi_value exports);
    static napi_value SubscribeTimeline(napi_env env, napi_callback_info info);
    static napi_value UnSubscribeTimeline(napi_env env, napi_callback_info info);
    static napi_value GetTimeline(napi_env env, napi_callback_info info);
	static napi_value EnumTimelineAreaConstructor(napi_env env, napi_callback_info info);
    static napi_value CreateEnumTimelineArea(napi_env env, napi_value exports);
    static napi_value EnumTimelineValueConstructor(napi_env env, napi_callback_info info);
    static napi_value CreateTimelineValueType(napi_env env, napi_value exports);
	static napi_status AddProperty(napi_env env, napi_value object, const std::string name, int32_t enumValue);
    static napi_value CreateTimelineValueObject(napi_env env);
    static napi_value SetPositionState(napi_env env, napi_callback_info info);
    static napi_value SetHomePosition(napi_env env, napi_callback_info info);
    static napi_value SetCompanyPosition(napi_env env, napi_callback_info info);
    static napi_value SetSleepTime(napi_env env, napi_callback_info info);
    static napi_value SetRestTime(napi_env env, napi_callback_info info);
    static napi_value SetWorkTime(napi_env env, napi_callback_info info);
    static napi_value GetForcecast(napi_env env, napi_callback_info info);
    static void InvokeCallBack(napi_env env, napi_value *args, bool voidParameter, int32_t value);

    static void RegisterCallback(const int32_t& eventType);
    void OnTimelineChangedDone(const int32_t& type, const int32_t& value);
    static TimelineNapi *GetTimelineNapi(int32_t area);
    static sptr<ITimelineCallback> callback_;
	static std::map<int32_t, sptr<ITimelineCallback>> callbackMap_;
    static std::map<int32_t, TimelineNapi*> objectMap_;

private:
    napi_ref callbackRef_;
	static napi_ref timelineValueRef_;
    napi_env env_;
};
} // namespace Msdp
} // namespace OHOS
#endif // TIMELINE_NAPI_H